# 1. 导包
import hashlib

import requests

# # 案例1：
# # 构造url
# url = r'https://www.httpbin.org/post'
# # 构造files
# files = {
#     'file': open(r'a.txt', mode='rb')
# }
# # 发送请求
# resp = requests.post(url, files=files)
# # 获得响应
# print(resp.text)

print('*'*50)

# # 案例2：百度通过图片进行搜索
# # 构造url
# url = r'https://graph.baidu.com/upload'
# # 构造 files
# files = {
#     'image': ('rose.png', open(r'rose.png', mode='rb'), 'image/png'),
#     "tn": 'pc',
#     "from": 'pc',
#     "image_source": 'PC_UPLOAD_FILE',
#     "sdkParams": '{"data": "4bba7cbbdbb3a718ba0a4561c27d3d3e568cc094461e4a86d8fae204ed46781e4dd561ce5897bc032a412e85656b541753fc99afbedfc49ffdbef562e4681ef3b25be9053697394c5807f7238a6a6151","key_id": "23", "sign": "b23fe2cf"}'
#
# }
# # 构造data
# data = {
#     'uptime': '1705046631789'
# }
# # 发送请求
# resp = requests.post(url,files=files)
# # 获取响应
# print(resp.text)
#

print('*'*50)
# 案例3：

# ------------------------- 登录 ----------------------------------

username = 'Missing'
password = 'h123456'
md5 = hashlib.md5(password.encode())
password_md5 = md5.hexdigest()
# 构造 url
url_base = r'https://cloud.huaxiaerp.com'
url_login = url_base + r'/jshERP-boot/user/login'
# 构造headers
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0',
    'Content-Type': 'application/json;charset=utf-8'
}
# 构造 data
data_login = {
    "loginName":username,
    "password":password_md5
}

# 发送请求
resp = requests.post(url_login, json=data_login, headers=headers, verify=False)
# 获取响应
resp = requests.post(url_login,json=data_login,headers=headers)
# 获取token
'''
从返回的json数据中，提取出 token
# # 不懂可以看这个
# # print(resp.json()['data'])
# # print(token)
'''
token =resp.json()['data']['token']

# 为后续功能构造请求头
headers['X-Access-Token'] = token

# ---------------------------------- 上传文件 -----------------------------
# 构造 url
url_upload = url_base + r'/jshERP-boot/systemConfig/upload'
# 构造file
files = {
    'file':('a.txt',open(r'a.txt',mode='rb'),'text/plain'),
    'biz':'bill'
}
# 发送请求

# 获取响应
